<!DOCTYPE html>
<html><head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Green-forest Framework Reference Guide</title>
	
	<link rel="stylesheet" type="text/css" href="css/reset.css">
	<link type="text/css" rel="stylesheet" href="css/shCoreDefault.css">
	<link rel="stylesheet" type="text/css" href="css/main.css">
	
	<script type="text/javascript" src="js/jquery-1.6.1-min.js"></script>
	<script type="text/javascript" src="js/jquery-ui-1.8.24.custom.min.js"></script>
	<script type="text/javascript" src="js/lang.js"></script>
	<script type="text/javascript" src="js/guide.js"></script>
	<script type="text/javascript" src="js/shCore.js"></script>
	<script type="text/javascript" src="js/shBrushJava.js"></script>
	<script type="text/javascript" src="js/shBrushXml.js"></script>
	<script type="text/javascript" src="js/effects.js"></script>
</head>
<body><span class="disablePreprocessingFlag"></span>
<div id="wrap">
	
	<div class="section">
		<a href="http://code.google.com/p/green-forest/">
			<img id="logo" src="i/gf-logo.png" alt="logo">
		</a>
		<h1>Green-forest Framework Reference Guide</h1>
	</div>
	
	<div class="section toc"><dl><dt><a href="#p1">1. Overview</a></dt><dt><a href="#p2">2. Features</a></dt><dt><a href="#p3">3. Install</a></dt><dt><a href="#p4">4. Getting Started</a></dt><dt><a href="#p5">5. Logging</a></dt><dt><a href="#p6">6. Configuration</a></dt><dt><a href="#p7">7. JEE Integration</a></dt><dt><a href="#p8">8. Spring Integration</a></dt><dt><a href="#p9">9. MyBatis Integration</a></dt><dt><a href="#p10">10. JDBC and Transactions</a></dt><dt><a href="#p11">11. Examples</a></dt><dt><a href="#p12">12. Known Issues</a></dt><dt><a href="#p13">13. Best Practices</a></dt><dt><a href="#p14">14. License</a></dt></dl></div>
	
	<div class="importBlock" p-url="./chapters/01_overview.html">
<h2><a id="p1">1. Overview</a></h2>

<p><span class="start-space"></span>
<span class="name">Green-forest Framework</span> is the simple <a href="#ioc-container">IoC Container</a> with <a href="#action-handler">Action-Handler architecture</a>. 
It's not a competitor for <span class="name">Spring Framework</span> or <span class="name">JEE</span> but it's a powerful addition for these frameworks. 
You can use <span class="name">Green-forest</span> for a single class implementation and for a complex business logic.</p></div>
	<div class="importBlock" p-url="./chapters/02_features.html"><h2><a id="p2">2. Features</a></h2>

<p><span class="start-space"></span>
<span class="title"><a id="ioc-container">IoC Container</a></span>
<br><span class="start-space"></span>With <span class="name">Green-forest</span> you can separate your application's logic into simple atomic classes. 
The framework organizes communications between this classes.
Also you can add an external object into invocation context and use it by dependency injection.

</p><p class="more-top"><span class="start-space"></span>
<span class="title"><a id="action-handler">Action-Handler architecture</a></span>
<br><span class="start-space"></span>API of <span class="name">Green-forest</span> has only one method: <tt>invoke</tt>. 
This method takes <a href="#action">Action</a> object with input data, finds targeted <a href="#handler">Handler</a> and return handler's output. 
<br><span class="start-space"></span>Take a look for the illustrating picture:
</p><div class="image-wrap">
	<img class="pic2" src="i/action-handler-pattern.png" width="90%">
	<div>Action-Handler architecture</div>
</div>
<p><span class="start-space"></span>Code example:
</p><div><div id="highlighter_700986" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java comments">//create Green-forest Engine</code></div><div class="line number2 index1 alt1"><code class="java plain">Engine engine = </code><code class="java keyword">new</code> <code class="java plain">Engine();</code></div><div class="line number3 index2 alt2"> </div><div class="line number4 index3 alt1"><code class="java comments">//register some handler</code></div><div class="line number5 index4 alt2"><code class="java plain">engine.putHandler(SomeActonHandler.</code><code class="java keyword">class</code><code class="java plain">);</code></div><div class="line number6 index5 alt1"> </div><div class="line number7 index6 alt2"><code class="java comments">//invoke some action and get result</code></div><div class="line number8 index7 alt1"><code class="java plain">String result = engine.invoke(</code><code class="java keyword">new</code> <code class="java plain">SomeAction(</code><code class="java string">"some data"</code><code class="java plain">));</code></div></div></td></tr></tbody></table></div></div>
	

<p class="more-top"><span class="start-space"></span>
<span class="title">Aspects implementation</span>
<br><span class="start-space"></span><span class="name">Green-forest</span> contains <a href="#aspects">Filters and Interceptors</a>. 
With these instruments you can implement a lot of aspects things (like <tt>validation</tt>, <tt>wrapping</tt>, <tt>logging</tt> etc)
without using special aspect libraries (like <span class="name">AspectJ</span>).
</p><p><span class="start-space"></span>Code example:
</p><div><div id="highlighter_447386" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">WorktimeFilter </code><code class="java keyword">extends</code> <code class="java plain">Filter {</code></div><div class="line number2 index1 alt1"> </div><div class="line number3 index2 alt2"><code class="java spaces">    </code><code class="java color1">@Override</code></div><div class="line number4 index3 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java keyword">void</code> <code class="java plain">invoke(Action&lt;?, ?&gt; action, FilterChain chain) </code></div><div class="line number5 index4 alt2"><code class="java spaces">        </code><code class="java keyword">throws</code> <code class="java plain">Exception {</code></div><div class="line number6 index5 alt1"><code class="java spaces">        </code> </div><div class="line number7 index6 alt2"><code class="java spaces">        </code><code class="java plain">Date begin = </code><code class="java keyword">new</code> <code class="java plain">Date();</code></div><div class="line number8 index7 alt1"><code class="java spaces">        </code><code class="java keyword">try</code> <code class="java plain">{</code></div><div class="line number9 index8 alt2"><code class="java spaces">            </code><code class="java comments">//next handler</code></div><div class="line number10 index9 alt1"><code class="java spaces">            </code><code class="java plain">chain.doNext();</code></div><div class="line number11 index10 alt2"><code class="java spaces">        </code><code class="java plain">}</code><code class="java keyword">finally</code> <code class="java plain">{</code></div><div class="line number12 index11 alt1"><code class="java spaces">            </code><code class="java keyword">long</code> <code class="java plain">worktime = System.currentTimeMillis() - begin.getTime();</code></div><div class="line number13 index12 alt2"><code class="java spaces">            </code><code class="java plain">log.info(</code><code class="java string">"worktime: "</code><code class="java plain">+worktime+</code><code class="java string">"ms"</code><code class="java plain">);</code></div><div class="line number14 index13 alt1"><code class="java spaces">        </code><code class="java plain">}</code></div><div class="line number15 index14 alt2"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number16 index15 alt1"> </div><div class="line number17 index16 alt2"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div>


<p class="more-top"><span class="start-space"></span>
<span class="title">Isolated contexts</span>
<br><span class="start-space"></span>You can use one <span class="name">Green-forest</span> inside another like external object.
In this way you can separate a big application context to few small isolated contexts that use each other.
<br><span class="start-space"></span>Take a look for the illustrating picture:
</p><div class="image-wrap">
	<img class="pic" src="i/isolated-context.png" width="90%">
	<div>Difference between single and isolated contexts</div>
</div>
<p><span class="start-space"></span>Code example:
</p><div><div id="highlighter_31477" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java comments">//Handler</code></div><div class="line number2 index1 alt1"><code class="java color1">@Mapping</code><code class="java plain">(SomeAction.</code><code class="java keyword">class</code><code class="java plain">)</code></div><div class="line number3 index2 alt2"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">SomeHandler </code><code class="java keyword">extends</code> <code class="java plain">Handler&lt;SomeAction&gt;{</code></div><div class="line number4 index3 alt1"> </div><div class="line number5 index4 alt2"><code class="java spaces">    </code><code class="java color1">@Inject</code></div><div class="line number6 index5 alt1"><code class="java spaces">    </code><code class="java plain">SomeService service;</code></div><div class="line number7 index6 alt2"><code class="java spaces">    </code> </div><div class="line number8 index7 alt1"><code class="java spaces">    </code><code class="java color1">@Inject</code></div><div class="line number9 index8 alt2"><code class="java spaces">    </code><code class="java plain">OtherService otherService;</code></div><div class="line number10 index9 alt1"><code class="java spaces">    </code> </div><div class="line number11 index10 alt2"><code class="java spaces">    </code><code class="java color1">@Override</code></div><div class="line number12 index11 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java keyword">void</code> <code class="java plain">invoke(SomeAction action) </code><code class="java keyword">throws</code> <code class="java plain">Exception {</code></div><div class="line number13 index12 alt2"><code class="java spaces">            </code> </div><div class="line number14 index13 alt1"><code class="java spaces">        </code><code class="java comments">//external object with action-handler API</code></div><div class="line number15 index14 alt2"><code class="java spaces">        </code><code class="java plain">service.invoke(</code><code class="java keyword">new</code> <code class="java plain">OtherAction());</code></div><div class="line number16 index15 alt1"><code class="java spaces">        </code> </div><div class="line number17 index16 alt2"><code class="java spaces">        </code><code class="java comments">//other external object</code></div><div class="line number18 index17 alt1"><code class="java spaces">        </code><code class="java plain">otherService.someMethod();</code></div><div class="line number19 index18 alt2"><code class="java spaces">        </code> </div><div class="line number20 index19 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number21 index20 alt2"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div></div>
	<div class="importBlock" p-url="./chapters/02.2_install.html"><h2><a id="p3">3. Install</a></h2>
	
<p><span class="start-space"></span>
<span class="title">Download from site</span>
<br><span class="start-space"></span>Get the latest version of <span class="name">Green-forest Framework</span> from <a target="_blank" href="https://code.google.com/p/green-forest/downloads/list">download page</a>.
The zip archive with name like <tt>"green-forest-X.X-pack.zip"</tt> contains binaries, javadocs and sources. 
<span class="name">Green-forest</span> has no dependencies for itself. Add the library to your Project.


</p><p class="more-top"><span class="start-space"></span>
<span class="title">For Maven project</span>
<br><span class="start-space"></span>Add to your <tt>pom.xml</tt> this dependency:
</p><div><div id="highlighter_716363" class="syntaxhighlighter  xml"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="xml plain">&lt;</code><code class="xml keyword">dependencies</code><code class="xml plain">&gt;</code></div><div class="line number2 index1 alt1"><code class="xml spaces">    </code><code class="xml plain">&lt;</code><code class="xml keyword">dependency</code><code class="xml plain">&gt;</code></div><div class="line number3 index2 alt2"><code class="xml spaces">        </code><code class="xml plain">&lt;</code><code class="xml keyword">groupId</code><code class="xml plain">&gt;com.gf&lt;/</code><code class="xml keyword">groupId</code><code class="xml plain">&gt;</code></div><div class="line number4 index3 alt1"><code class="xml spaces">        </code><code class="xml plain">&lt;</code><code class="xml keyword">artifactId</code><code class="xml plain">&gt;green-forest&lt;/</code><code class="xml keyword">artifactId</code><code class="xml plain">&gt;</code></div><div class="line number5 index4 alt2"><code class="xml spaces">        </code><code class="xml plain">&lt;</code><code class="xml keyword">version</code><code class="xml plain">&gt;0.9&lt;/</code><code class="xml keyword">version</code><code class="xml plain">&gt;</code></div><div class="line number6 index5 alt1"><code class="xml spaces">    </code><code class="xml plain">&lt;/</code><code class="xml keyword">dependency</code><code class="xml plain">&gt;</code></div><div class="line number7 index6 alt2"><code class="xml plain">&lt;/</code><code class="xml keyword">dependencies</code><code class="xml plain">&gt;</code></div><div class="line number8 index7 alt1"><code class="xml spaces"> </code> </div><div class="line number9 index8 alt2"><code class="xml plain">&lt;</code><code class="xml keyword">repositories</code><code class="xml plain">&gt;</code></div><div class="line number10 index9 alt1"><code class="xml spaces">    </code><code class="xml plain">&lt;</code><code class="xml keyword">repository</code><code class="xml plain">&gt;</code></div><div class="line number11 index10 alt2"><code class="xml spaces">        </code><code class="xml plain">&lt;</code><code class="xml keyword">id</code><code class="xml plain">&gt;green-forest-repo&lt;/</code><code class="xml keyword">id</code><code class="xml plain">&gt;</code></div><div class="line number12 index11 alt1"><code class="xml spaces">        </code><code class="xml plain">&lt;</code><code class="xml keyword">url</code><code class="xml plain">&gt;<a href="http://green-forest.googlecode.com/svn/repo/">http://green-forest.googlecode.com/svn/repo/</a>&lt;/</code><code class="xml keyword">url</code><code class="xml plain">&gt;</code></div><div class="line number13 index12 alt2"><code class="xml spaces">    </code><code class="xml plain">&lt;/</code><code class="xml keyword">repository</code><code class="xml plain">&gt;</code></div><div class="line number14 index13 alt1"><code class="xml plain">&lt;/</code><code class="xml keyword">repositories</code><code class="xml plain">&gt;</code></div></div></td></tr></tbody></table></div></div></div>
	<div class="importBlock" p-url="./chapters/03_getting-started.html"><h2><a id="p4">4. Getting Started</a></h2>
	
<p><span class="start-space"></span>
<span class="title">I. Create Actions</span>
</p><div class="def">
	<p><span class="start-space"></span><b><a id="action">Action</a></b> presents some atomic logic operation (like function in interface) 
	and contains input and output data. 
</p></div>
<p><span class="start-space"></span>For example we have <tt>Doc</tt> class for presents some document object. 
So in our app we can create actions like 
<tt>CreateDoc</tt>, 
<tt>RenameDoc</tt>, 
<tt>DeleteDoc</tt> for working with documents. 
And <tt>CreateDoc</tt> for example has input <tt>String</tt> (name of the doc) and output <tt>Doc</tt> (created object):

</p><div><div id="highlighter_946398" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java keyword">import</code> <code class="java plain">com.gf.Action;</code></div><div class="line number2 index1 alt1"> </div><div class="line number3 index2 alt2"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">CreateDoc </code><code class="java keyword">extends</code> <code class="java plain">Action&lt;String, Doc&gt;{</code></div><div class="line number4 index3 alt1"> </div><div class="line number5 index4 alt2"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java plain">CreateDoc(String name) {</code></div><div class="line number6 index5 alt1"><code class="java spaces">        </code><code class="java keyword">super</code><code class="java plain">(name);</code></div><div class="line number7 index6 alt2"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number8 index7 alt1"><code class="java spaces">    </code> </div><div class="line number9 index8 alt2"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div>


<p class="more-top"><span class="start-space"></span>
<span class="title">II. Create Handlers</span>
</p><div class="def">
	<p><span class="start-space"></span><b><a id="handler">Handler</a></b> implements logic of the action (like interface function's implementation). 
	It uses Action object for taking input data and setting output data.
</p></div>
<p><span class="start-space"></span>Note: Handler must contains <tt>@Mapping</tt> annotation.
</p><p><span class="start-space"></span>Let's implement <tt>CreateDoc</tt> logic:
</p><div><div id="highlighter_25426" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java keyword">import</code> <code class="java plain">com.gf.Handler;</code></div><div class="line number2 index1 alt1"><code class="java keyword">import</code> <code class="java plain">com.gf.annotation.Mapping;</code></div><div class="line number3 index2 alt2"> </div><div class="line number4 index3 alt1"><code class="java keyword">import</code> <code class="java plain">foo.Storage;</code></div><div class="line number5 index4 alt2"> </div><div class="line number6 index5 alt1"><code class="java color1">@Mapping</code><code class="java plain">(CreateDoc.</code><code class="java keyword">class</code><code class="java plain">)</code></div><div class="line number7 index6 alt2"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">CreateDocHandler </code><code class="java keyword">extends</code> <code class="java plain">Handler&lt;CreateDoc&gt;{</code></div><div class="line number8 index7 alt1"> </div><div class="line number9 index8 alt2"><code class="java spaces">    </code><code class="java color1">@Inject</code></div><div class="line number10 index9 alt1"><code class="java spaces">    </code><code class="java plain">Storage storage;</code></div><div class="line number11 index10 alt2"><code class="java spaces">    </code> </div><div class="line number12 index11 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java keyword">void</code> <code class="java plain">invoke(CreateDoc action) </code><code class="java keyword">throws</code> <code class="java plain">Exception {</code></div><div class="line number13 index12 alt2"><code class="java spaces">    </code> </div><div class="line number14 index13 alt1"><code class="java spaces">        </code><code class="java plain">String name = action.getInput();</code></div><div class="line number15 index14 alt2"><code class="java spaces">        </code><code class="java plain">Doc created = storage.createNewDoc(name);</code></div><div class="line number16 index15 alt1"><code class="java spaces">        </code> </div><div class="line number17 index16 alt2"><code class="java spaces">        </code><code class="java plain">action.setOutput(created);</code></div><div class="line number18 index17 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number19 index18 alt2"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div>

	
<p class="more-top"><span class="start-space"></span>
<span class="title">III. Connect actions with handlers by Engine</span>
</p><div class="def">
	<p><span class="start-space"></span><b><a id="engine">Engine</a></b> is the central class of <span class="name">Green-forest Framework</span>. 
	Use it for create object with Action-Handler API.
</p></div>
<div><div id="highlighter_843334" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java keyword">import</code> <code class="java plain">com.gf.core.Engine;</code></div><div class="line number2 index1 alt1"> </div><div class="line number3 index2 alt2"><code class="java plain">Engine engine = </code><code class="java keyword">new</code> <code class="java plain">Engine();</code></div><div class="line number4 index3 alt1"><code class="java plain">engine.addToContext(storage);</code></div><div class="line number5 index4 alt2"><code class="java plain">engine.putHandler(CreateDocHandler.</code><code class="java keyword">class</code><code class="java plain">);</code></div><div class="line number6 index5 alt1"> </div><div class="line number7 index6 alt2"><code class="java plain">Doc result = engine.invoke(</code><code class="java keyword">new</code> <code class="java plain">CreateDoc(</code><code class="java string">"some name"</code><code class="java plain">));</code></div></div></td></tr></tbody></table></div></div>

<p class="more-top"><span class="start-space"></span>
<span class="title">IV. Use class scanner</span>
<br><span class="start-space"></span>If you have a set of handlers, interceptors and filters you can add all of them by package scanning:
</p><div><div id="highlighter_713420" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java keyword">import</code> <code class="java plain">com.gf.core.Engine;</code></div><div class="line number2 index1 alt1"> </div><div class="line number3 index2 alt2"><code class="java plain">Engine engine = </code><code class="java keyword">new</code> <code class="java plain">Engine();</code></div><div class="line number4 index3 alt1"> </div><div class="line number5 index4 alt2"><code class="java comments">//put all valid handlers, interceptors and filters</code></div><div class="line number6 index5 alt1"><code class="java plain">engine.scanAndPut(</code><code class="java string">"foo.bar"</code><code class="java plain">);</code></div><div class="line number7 index6 alt2"> </div><div class="line number8 index7 alt1"><code class="java plain">Doc result = engine.invoke(</code><code class="java keyword">new</code> <code class="java plain">CreateDoc(</code><code class="java string">"some name"</code><code class="java plain">));</code></div></div></td></tr></tbody></table></div></div>


<p class="more-top"><span class="start-space"></span>
<span class="title">V. Create understandable interface</span>
<br><span class="start-space"></span>Use understandable name of your API not just the universal <tt>Engine</tt>.
For this reason you can extend <tt>ActionService</tt> interface: 
</p><div><div id="highlighter_157357" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java keyword">import</code> <code class="java plain">com.gf.service.ActionService;</code></div><div class="line number2 index1 alt1"> </div><div class="line number3 index2 alt2"><code class="java keyword">public</code> <code class="java keyword">interface</code> <code class="java plain">DocService </code><code class="java keyword">extends</code> <code class="java plain">ActionService { }</code></div><div class="line number4 index3 alt1"> </div><div class="line number5 index4 alt2"> </div><div class="line number6 index5 alt1"><code class="java comments">//example of service using</code></div><div class="line number7 index6 alt2"><code class="java plain">DocService service = getService();</code></div><div class="line number8 index7 alt1"><code class="java plain">Doc result = service.invoke(</code><code class="java keyword">new</code> <code class="java plain">CreateDoc(</code><code class="java string">"some name"</code><code class="java plain">));</code></div></div></td></tr></tbody></table></div></div>

<p><span class="start-space"></span>And create implementation with <tt>Engine</tt> inside:
</p><div><div id="highlighter_117137" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java keyword">import</code> <code class="java plain">com.gf.core.Engine;</code></div><div class="line number2 index1 alt1"><code class="java keyword">import</code> <code class="java plain">foo.Storage;</code></div><div class="line number3 index2 alt2"> </div><div class="line number4 index3 alt1"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">DocServiceImpl </code><code class="java keyword">implements</code> <code class="java plain">DocService {</code></div><div class="line number5 index4 alt2"> </div><div class="line number6 index5 alt1"><code class="java spaces">    </code><code class="java keyword">private</code> <code class="java plain">Engine engine;</code></div><div class="line number7 index6 alt2"> </div><div class="line number8 index7 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java plain">DocServiceImpl() {</code></div><div class="line number9 index8 alt2"><code class="java spaces">    </code> </div><div class="line number10 index9 alt1"><code class="java spaces">        </code><code class="java plain">Storage storage = </code><code class="java keyword">new</code> <code class="java plain">Storage();</code></div><div class="line number11 index10 alt2"><code class="java spaces">        </code> </div><div class="line number12 index11 alt1"><code class="java spaces">        </code><code class="java plain">engine = </code><code class="java keyword">new</code> <code class="java plain">Engine();</code></div><div class="line number13 index12 alt2"><code class="java spaces">        </code><code class="java plain">engine.addToContext(storage);</code></div><div class="line number14 index13 alt1"><code class="java spaces">        </code><code class="java plain">engine.putHandler(CreateDocHandler.</code><code class="java keyword">class</code><code class="java plain">);</code></div><div class="line number15 index14 alt2"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number16 index15 alt1"><code class="java spaces">    </code> </div><div class="line number17 index16 alt2"><code class="java spaces">    </code> </div><div class="line number18 index17 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java plain">&lt;I, O&gt; O invoke(Action&lt;I, O&gt; action) {</code></div><div class="line number19 index18 alt2"><code class="java spaces">        </code><code class="java keyword">return</code> <code class="java plain">engine.invoke(action);</code></div><div class="line number20 index19 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number21 index20 alt2"><code class="java spaces">    </code> </div><div class="line number22 index21 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java plain">&lt;I, O&gt; O invokeUnwrap(Action&lt;I, O&gt; action) </code><code class="java keyword">throws</code> <code class="java plain">Exception {</code></div><div class="line number23 index22 alt2"><code class="java spaces">        </code><code class="java keyword">return</code> <code class="java plain">engine.invokeUnwrap(action);</code></div><div class="line number24 index23 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number25 index24 alt2"> </div><div class="line number26 index25 alt1"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div>


<p class="more-top"><span class="start-space"></span>
<span class="title"><a id="aspects">VI. Add aspects things</a></span>
<br><span class="start-space"></span>In next step you can use <tt>Filters</tt> and <tt>Interveptors</tt> for aspects (like validation or security).
</p><p><span class="start-space"></span>Example of security filter:
</p><div><div id="highlighter_614067" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java keyword">import</code> <code class="java plain">com.gf.Filter;</code></div><div class="line number2 index1 alt1"> </div><div class="line number3 index2 alt2"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">SecurityFilter </code><code class="java keyword">extends</code> <code class="java plain">Filter {</code></div><div class="line number4 index3 alt1"><code class="java spaces">    </code> </div><div class="line number5 index4 alt2"><code class="java spaces">    </code><code class="java color1">@Override</code></div><div class="line number6 index5 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java keyword">void</code> <code class="java plain">invoke(Action&lt;?, ?&gt; action, FilterChain chain) </code></div><div class="line number7 index6 alt2"><code class="java spaces">            </code><code class="java keyword">throws</code> <code class="java plain">Exception {</code></div><div class="line number8 index7 alt1"><code class="java spaces">        </code> </div><div class="line number9 index8 alt2"><code class="java spaces">        </code><code class="java keyword">boolean</code> <code class="java plain">isPermitted = checkUserPermissions();</code></div><div class="line number10 index9 alt1"><code class="java spaces">        </code> </div><div class="line number11 index10 alt2"><code class="java spaces">        </code><code class="java keyword">if</code><code class="java plain">( ! isPermitted) </code><code class="java keyword">throw</code> <code class="java keyword">new</code> <code class="java plain">SecutiryException();</code></div><div class="line number12 index11 alt1"><code class="java spaces">        </code><code class="java keyword">else</code> <code class="java plain">chain.doNext();</code></div><div class="line number13 index12 alt2"><code class="java spaces">        </code> </div><div class="line number14 index13 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number15 index14 alt2"> </div><div class="line number16 index15 alt1"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div>

<p><span class="start-space"></span>And example of validation interceptor:
</p><div><div id="highlighter_500436" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java keyword">import</code> <code class="java plain">com.gf.Interceptor;</code></div><div class="line number2 index1 alt1"><code class="java keyword">import</code> <code class="java plain">com.gf.annotation.Mapping;</code></div><div class="line number3 index2 alt2"> </div><div class="line number4 index3 alt1"><code class="java color1">@Mapping</code><code class="java plain">(CreateDoc.</code><code class="java keyword">class</code><code class="java plain">)</code></div><div class="line number5 index4 alt2"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">CheckNameInterceptor </code><code class="java keyword">extends</code> <code class="java plain">Interceptor&lt;CreateDoc&gt;{</code></div><div class="line number6 index5 alt1"> </div><div class="line number7 index6 alt2"><code class="java spaces">    </code><code class="java color1">@Override</code></div><div class="line number8 index7 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java keyword">void</code> <code class="java plain">invoke(CreateDoc action, InterceptorChain chain)</code></div><div class="line number9 index8 alt2"><code class="java spaces">            </code><code class="java keyword">throws</code> <code class="java plain">Exception {</code></div><div class="line number10 index9 alt1"><code class="java spaces">        </code> </div><div class="line number11 index10 alt2"><code class="java spaces">        </code><code class="java plain">String name = action.input();</code></div><div class="line number12 index11 alt1"><code class="java spaces">        </code><code class="java keyword">if</code><code class="java plain">(name == </code><code class="java keyword">null</code></div><div class="line number13 index12 alt2"><code class="java spaces">                </code><code class="java plain">|| name.length() == </code><code class="java value">0</code><code class="java plain">)</code></div><div class="line number14 index13 alt1"><code class="java spaces">            </code><code class="java keyword">throw</code> <code class="java keyword">new</code> <code class="java plain">InvalidNameException();</code></div><div class="line number15 index14 alt2"><code class="java spaces">        </code> </div><div class="line number16 index15 alt1"><code class="java spaces">        </code><code class="java plain">chain.doNext();</code></div><div class="line number17 index16 alt2"><code class="java spaces">        </code> </div><div class="line number18 index17 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number19 index18 alt2"> </div><div class="line number20 index19 alt1"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div></div>
	<div class="importBlock" p-url="./chapters/08_logging.html"><h2><a id="p5">5. Logging</a></h2>

<p><span class="start-space"></span><span class="name">Green-forest Framework</span> contains own <a target="_blank" href="../javadoc/com/gf/log/Log.html">Logger</a> interface. 
You can use it in handlers, interceptors and filters:
</p><div><div id="highlighter_550586" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java color1">@Mapping</code><code class="java plain">(SomeAction.</code><code class="java keyword">class</code><code class="java plain">)</code></div><div class="line number2 index1 alt1"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">SomeActonHandler </code><code class="java keyword">extends</code> <code class="java plain">Handler&lt;SomeAction&gt;{</code></div><div class="line number3 index2 alt2"> </div><div class="line number4 index3 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java keyword">void</code> <code class="java plain">invoke(SomeAction action) </code><code class="java keyword">throws</code> <code class="java plain">Exception {</code></div><div class="line number5 index4 alt2"><code class="java spaces">        </code> </div><div class="line number6 index5 alt1"><code class="java spaces">        </code><code class="java plain">log.info(</code><code class="java string">"some log message"</code><code class="java plain">);</code></div><div class="line number7 index6 alt2"><code class="java spaces">        </code> </div><div class="line number8 index7 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number9 index8 alt2"> </div><div class="line number10 index9 alt1"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div>

<p><span class="start-space"></span>
If your app contains <span class="name">commons-logging</span> or <span class="name">slf4j</span> log library 
then <span class="name">Green-forest</span> will use an appropriate wrapper.

</p><p class="text-align-left"><span class="start-space"></span>
For using your own implementation of <a target="_blank" href="../javadoc/com/gf/log/Log.html">Logger</a> interface
create custom <a target="_blank" href="../javadoc/com/gf/log/LogProvider.html">LogProvider</a> and set 
<tt>"com.gf.log.LogProvider"</tt> system property:

</p><div><div id="highlighter_243023" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java comments">//factory impl</code></div><div class="line number2 index1 alt1"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">CustomLogProvider </code><code class="java keyword">implements</code> <code class="java plain">LogProvider {</code></div><div class="line number3 index2 alt2"> </div><div class="line number4 index3 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java plain">Log getLog(Class&lt;?&gt; clazz) {</code></div><div class="line number5 index4 alt2"><code class="java spaces">        </code><code class="java keyword">return</code> <code class="java keyword">new</code> <code class="java plain">CustomLogImpl(clazz);</code></div><div class="line number6 index5 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number7 index6 alt2"> </div><div class="line number8 index7 alt1"><code class="java plain">}</code></div><div class="line number9 index8 alt2"> </div><div class="line number10 index9 alt1"><code class="java comments">//setup on start</code></div><div class="line number11 index10 alt2"><code class="java plain">java -Dcom.gf.log.LogProvider=foo.blah.CustomLogProvider</code></div><div class="line number12 index11 alt1"> </div><div class="line number13 index12 alt2"><code class="java comments">//or setup in app BEFORE first call of Green-forest</code></div><div class="line number14 index13 alt1"><code class="java keyword">static</code> <code class="java plain">{</code></div><div class="line number15 index14 alt2"><code class="java spaces">    </code><code class="java plain">System.setProperty(</code><code class="java string">"com.gf.log.LogProvider"</code><code class="java plain">, </code><code class="java string">"foo.blah.CustomLogProvider"</code><code class="java plain">);</code></div><div class="line number16 index15 alt1"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div></div>
	<div class="importBlock" p-url="./chapters/08.2_config.html"><h2><a id="p6">6. Configuration</a></h2>

<span class="title">Trace invocation</span>
<br>
You can enable a trace information by <a target="_blank" href="../javadoc/com/gf/key/TraceHandlers.html">TraceHandlers</a> key:
<div><div id="highlighter_200674" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java keyword">import</code> <code class="java plain">com.gf.key.TraceHandlers;</code></div><div class="line number2 index1 alt1"><code class="java keyword">import</code> <code class="java plain">com.gf.extra.trace.Trace;</code></div><div class="line number3 index2 alt2"> </div><div class="line number4 index3 alt1"><code class="java plain">Engine engine = </code><code class="java keyword">new</code> <code class="java plain">Engine();</code></div><div class="line number5 index4 alt2"><code class="java plain">engine.setConfig(TraceHandlers.</code><code class="java keyword">class</code><code class="java plain">, </code><code class="java keyword">true</code><code class="java plain">); </code><code class="java comments">//enable tracing</code></div><div class="line number6 index5 alt1"><code class="java plain">...</code></div><div class="line number7 index6 alt2"><code class="java plain">SomeAction someActon = </code><code class="java keyword">new</code> <code class="java plain">SomeAction();</code></div><div class="line number8 index7 alt1"><code class="java plain">engine.invoke(someActon);</code></div><div class="line number9 index8 alt2"><code class="java spaces">     </code> </div><div class="line number10 index9 alt1"><code class="java plain">Trace trace = TraceHandlers.getTrace(someActon); </code><code class="java comments">//get trace info from the action</code></div></div></td></tr></tbody></table></div></div></div>
	<div class="importBlock" p-url="./chapters/04_jee.html">
<h2><a id="p7">7. JEE Integration</a></h2>

<p><span class="start-space"></span>Use <span class="name">Green-forest Framework</span> in <tt>Statless</tt> or <tt>Singleton</tt> beans for creating Action-Handler API instead of classic API.
You can use <span class="name">JEE</span> features like context objects in your <a href="#engine">Engine</a> and inject them to handlers.
<br><span class="start-space"></span>Example of classic <span class="name">JEE</span> interface and implementation:
</p><div><div id="highlighter_165549" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div><div class="line number28 index27 alt1">28</div><div class="line number29 index28 alt2">29</div><div class="line number30 index29 alt1">30</div><div class="line number31 index30 alt2">31</div><div class="line number32 index31 alt1">32</div><div class="line number33 index32 alt2">33</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java keyword">import</code> <code class="java plain">foo.Doc</code></div><div class="line number2 index1 alt1"> </div><div class="line number3 index2 alt2"><code class="java comments">//interface</code></div><div class="line number4 index3 alt1"><code class="java keyword">public</code> <code class="java keyword">interface</code> <code class="java plain">SomeService {</code></div><div class="line number5 index4 alt2"><code class="java spaces">    </code> </div><div class="line number6 index5 alt1"><code class="java spaces">    </code><code class="java plain">Doc createDoc(String name);</code></div><div class="line number7 index6 alt2"><code class="java spaces">    </code> </div><div class="line number8 index7 alt1"><code class="java spaces">    </code><code class="java plain">Doc getDoc(</code><code class="java keyword">int</code> <code class="java plain">id);</code></div><div class="line number9 index8 alt2"><code class="java spaces">    </code> </div><div class="line number10 index9 alt1"><code class="java spaces">    </code><code class="java keyword">void</code> <code class="java plain">deleteDoc(</code><code class="java keyword">int</code> <code class="java plain">id);</code></div><div class="line number11 index10 alt2"> </div><div class="line number12 index11 alt1"><code class="java plain">}</code></div><div class="line number13 index12 alt2"> </div><div class="line number14 index13 alt1"><code class="java comments">//implementation</code></div><div class="line number15 index14 alt2"><code class="java color1">@Stateless</code></div><div class="line number16 index15 alt1"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">SomeBean </code><code class="java keyword">implements</code> <code class="java plain">SomeService {</code></div><div class="line number17 index16 alt2"><code class="java spaces">    </code> </div><div class="line number18 index17 alt1"><code class="java spaces">    </code><code class="java color1">@PersistenceContext</code></div><div class="line number19 index18 alt2"><code class="java spaces">    </code><code class="java plain">EntityManager entityManager;</code></div><div class="line number20 index19 alt1"> </div><div class="line number21 index20 alt2"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java plain">Doc createDoc(String name) {</code></div><div class="line number22 index21 alt1"><code class="java spaces">        </code><code class="java comments">//some impl</code></div><div class="line number23 index22 alt2"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number24 index23 alt1"> </div><div class="line number25 index24 alt2"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java plain">Doc getDoc(</code><code class="java keyword">int</code> <code class="java plain">id) {</code></div><div class="line number26 index25 alt1"><code class="java spaces">        </code><code class="java comments">//some impl</code></div><div class="line number27 index26 alt2"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number28 index27 alt1"> </div><div class="line number29 index28 alt2"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java keyword">void</code> <code class="java plain">deleteDoc(</code><code class="java keyword">int</code> <code class="java plain">id) {</code></div><div class="line number30 index29 alt1"><code class="java spaces">        </code><code class="java comments">//some impl</code></div><div class="line number31 index30 alt2"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number32 index31 alt1"> </div><div class="line number33 index32 alt2"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div>

<br>
<a id="jee5impl"></a>Example of refactoring this API to Action-Hanlder API:
<div><div id="highlighter_734274" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java keyword">import</code> <code class="java plain">com.gf.components.jee.ActionServiceBean;</code></div><div class="line number2 index1 alt1"><code class="java keyword">import</code> <code class="java plain">com.gf.core.Engine;</code></div><div class="line number3 index2 alt2"><code class="java keyword">import</code> <code class="java plain">com.gf.service.ActionService;</code></div><div class="line number4 index3 alt1"> </div><div class="line number5 index4 alt2"><code class="java comments">//interface</code></div><div class="line number6 index5 alt1"><code class="java keyword">public</code> <code class="java keyword">interface</code> <code class="java plain">OtherService </code><code class="java keyword">extends</code> <code class="java plain">ActionService { }</code></div><div class="line number7 index6 alt2"> </div><div class="line number8 index7 alt1"> </div><div class="line number9 index8 alt2"><code class="java comments">//implementation</code></div><div class="line number10 index9 alt1"><code class="java color1">@Stateless</code></div><div class="line number11 index10 alt2"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">OtherBean </code><code class="java keyword">extends</code> <code class="java plain">ActionServiceBean </code><code class="java keyword">implements</code> <code class="java plain">OtherService {</code></div><div class="line number12 index11 alt1"><code class="java spaces">    </code> </div><div class="line number13 index12 alt2"><code class="java spaces">    </code><code class="java color1">@PersistenceContext</code></div><div class="line number14 index13 alt1"><code class="java spaces">    </code><code class="java plain">EntityManager entityManager;</code></div><div class="line number15 index14 alt2"> </div><div class="line number16 index15 alt1"><code class="java spaces">    </code><code class="java comments">//create singleton intance</code></div><div class="line number17 index16 alt2"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java plain">ActionService createActionService() {</code></div><div class="line number18 index17 alt1"><code class="java spaces">        </code> </div><div class="line number19 index18 alt2"><code class="java spaces">        </code><code class="java comments">//create engine</code></div><div class="line number20 index19 alt1"><code class="java spaces">        </code><code class="java plain">Engine engine = </code><code class="java keyword">new</code> <code class="java plain">Engine();</code></div><div class="line number21 index20 alt2"><code class="java spaces">        </code><code class="java plain">engine.addToContext(entityManager);</code></div><div class="line number22 index21 alt1"><code class="java spaces">        </code><code class="java plain">engine.scanAndPut(</code><code class="java string">"foo.blah"</code><code class="java plain">);</code></div><div class="line number23 index22 alt2"> </div><div class="line number24 index23 alt1"><code class="java spaces">        </code><code class="java keyword">return</code> <code class="java plain">engine;</code></div><div class="line number25 index24 alt2"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number26 index25 alt1"><code class="java spaces">    </code> </div><div class="line number27 index26 alt2"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div>

<p class="more-top"><span class="start-space"></span>
<span class="title">JEE 5</span>
<br><span class="start-space"></span>
In JEE 5 there is no a standart singleton bean. 
<br><span class="start-space"></span>So you can extend <a target="_blank" href="../javadoc/com/gf/components/jee/ActionServiceBean.html"><tt>ActionServiceBean</tt></a> for Engine storing 
(see <a href="#jee5impl">example above</a>).


</p><p class="more-top"><span class="start-space"></span>
<span class="title">JEE 6</span>
<br><span class="start-space"></span>
In JEE 6 you can use Singleton bean:
<br><span class="start-space"></span>Example of JEE 6 Action-Hanlder API:
</p><div><div id="highlighter_624355" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div><div class="line number28 index27 alt1">28</div><div class="line number29 index28 alt2">29</div><div class="line number30 index29 alt1">30</div><div class="line number31 index30 alt2">31</div><div class="line number32 index31 alt1">32</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java keyword">import</code> <code class="java plain">com.gf.core.Engine;</code></div><div class="line number2 index1 alt1"><code class="java keyword">import</code> <code class="java plain">com.gf.service.ActionService;</code></div><div class="line number3 index2 alt2"> </div><div class="line number4 index3 alt1"><code class="java comments">//interface</code></div><div class="line number5 index4 alt2"><code class="java keyword">public</code> <code class="java keyword">interface</code> <code class="java plain">OtherService </code><code class="java keyword">extends</code> <code class="java plain">ActionService { }</code></div><div class="line number6 index5 alt1"> </div><div class="line number7 index6 alt2"> </div><div class="line number8 index7 alt1"><code class="java comments">//implementation</code></div><div class="line number9 index8 alt2"><code class="java color1">@Singleton</code></div><div class="line number10 index9 alt1"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">OtherBean </code><code class="java keyword">implements</code> <code class="java plain">OtherService {</code></div><div class="line number11 index10 alt2"><code class="java spaces">    </code> </div><div class="line number12 index11 alt1"><code class="java spaces">    </code><code class="java color1">@PersistenceContext</code></div><div class="line number13 index12 alt2"><code class="java spaces">    </code><code class="java plain">EntityManager entityManager;</code></div><div class="line number14 index13 alt1"><code class="java spaces">    </code> </div><div class="line number15 index14 alt2"><code class="java spaces">    </code><code class="java plain">Engine engine;</code></div><div class="line number16 index15 alt1"><code class="java spaces">    </code> </div><div class="line number17 index16 alt2"><code class="java spaces">    </code><code class="java color1">@PostConstruct</code></div><div class="line number18 index17 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java keyword">void</code> <code class="java plain">createEngine(){</code></div><div class="line number19 index18 alt2"><code class="java spaces">        </code><code class="java plain">engine = </code><code class="java keyword">new</code> <code class="java plain">Engine();</code></div><div class="line number20 index19 alt1"><code class="java spaces">        </code><code class="java plain">engine.addToContext(entityManager);</code></div><div class="line number21 index20 alt2"><code class="java spaces">        </code><code class="java plain">engine.scanAndPut(</code><code class="java string">"foo.blah"</code><code class="java plain">);</code></div><div class="line number22 index21 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number23 index22 alt2"><code class="java spaces">    </code> </div><div class="line number24 index23 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java plain">&lt;I, O&gt; O invoke(Action&lt;I, O&gt; action) {</code></div><div class="line number25 index24 alt2"><code class="java spaces">        </code><code class="java keyword">return</code> <code class="java plain">(O) engine.invoke(action);</code></div><div class="line number26 index25 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number27 index26 alt2"> </div><div class="line number28 index27 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java plain">&lt;I, O&gt; O invokeUnwrap(Action&lt;I, O&gt; action) </code><code class="java keyword">throws</code> <code class="java plain">Exception {</code></div><div class="line number29 index28 alt2"><code class="java spaces">        </code><code class="java keyword">return</code> <code class="java plain">(O) engine.invokeUnwrap(action);</code></div><div class="line number30 index29 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number31 index30 alt2"><code class="java spaces">    </code> </div><div class="line number32 index31 alt1"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div>

<p><span class="start-space"></span>
</p><div class="def">
	See example of <span class="name">JEE</span> app <a target="_blank" href="./example-jee.html">here</a>.
</div></div>
	<div class="importBlock" p-url="./chapters/05_spring.html">
<h2><a id="p8">8. Spring Integration</a></h2>

<p><span class="start-space"></span>Use <span class="name">Green-forest Framework</span> in <span class="name">Spring Framework</span> like Spring bean for creating Action-Handler API instead of classic API.
You can use <span class="name">Spring Framework</span> features like context objects in your <a href="#engine">Engine</a> and inject them to handlers.
<br><span class="start-space"></span>Example of Engine's bean in Spring config file:
</p><div><div id="highlighter_372413" class="syntaxhighlighter  xml"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="xml plain">&lt;</code><code class="xml keyword">beans</code> <code class="xml plain">...&gt;</code></div><div class="line number2 index1 alt1"> </div><div class="line number3 index2 alt2"><code class="xml spaces">    </code><code class="xml plain">&lt;</code><code class="xml keyword">bean</code> <code class="xml color1">id</code><code class="xml plain">=</code><code class="xml string">"someEngine"</code> <code class="xml color1">class</code><code class="xml plain">=</code><code class="xml string">"com.gf.core.Engine"</code><code class="xml plain">&gt;</code></div><div class="line number4 index3 alt1"><code class="xml spaces">        </code><code class="xml plain">&lt;</code><code class="xml keyword">property</code> <code class="xml color1">name</code><code class="xml plain">=</code><code class="xml string">"scanAndPut"</code><code class="xml plain">&gt;</code></div><div class="line number5 index4 alt2"><code class="xml spaces">            </code><code class="xml plain">&lt;</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number6 index5 alt1"><code class="xml spaces">                </code><code class="xml plain">&lt;</code><code class="xml keyword">value</code><code class="xml plain">&gt;foo.blah&lt;/</code><code class="xml keyword">value</code><code class="xml plain">&gt;</code></div><div class="line number7 index6 alt2"><code class="xml spaces">            </code><code class="xml plain">&lt;/</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number8 index7 alt1"><code class="xml spaces">        </code><code class="xml plain">&lt;/</code><code class="xml keyword">property</code><code class="xml plain">&gt;</code></div><div class="line number9 index8 alt2"><code class="xml spaces">        </code><code class="xml plain">&lt;</code><code class="xml keyword">property</code> <code class="xml color1">name</code><code class="xml plain">=</code><code class="xml string">"contextObjects"</code><code class="xml plain">&gt;</code></div><div class="line number10 index9 alt1"><code class="xml spaces">            </code><code class="xml plain">&lt;</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number11 index10 alt2"><code class="xml spaces">                </code><code class="xml plain">&lt;</code><code class="xml keyword">ref</code> <code class="xml color1">bean</code><code class="xml plain">=</code><code class="xml string">"someBean"</code><code class="xml plain">/&gt;</code></div><div class="line number12 index11 alt1"><code class="xml spaces">                </code><code class="xml plain">&lt;</code><code class="xml keyword">ref</code> <code class="xml color1">bean</code><code class="xml plain">=</code><code class="xml string">"otherBean"</code><code class="xml plain">/&gt;</code></div><div class="line number13 index12 alt2"><code class="xml spaces">            </code><code class="xml plain">&lt;/</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number14 index13 alt1"><code class="xml spaces">        </code><code class="xml plain">&lt;/</code><code class="xml keyword">property</code><code class="xml plain">&gt;</code></div><div class="line number15 index14 alt2"><code class="xml spaces">        </code><code class="xml plain">&lt;</code><code class="xml keyword">property</code> <code class="xml color1">name</code><code class="xml plain">=</code><code class="xml string">"filterTypes"</code><code class="xml plain">&gt;</code></div><div class="line number16 index15 alt1"><code class="xml spaces">            </code><code class="xml plain">&lt;</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number17 index16 alt2"><code class="xml spaces">                </code><code class="xml plain">&lt;</code><code class="xml keyword">value</code><code class="xml plain">&gt;bar.baz.SomeFilter&lt;/</code><code class="xml keyword">value</code><code class="xml plain">&gt;</code></div><div class="line number18 index17 alt1"><code class="xml spaces">            </code><code class="xml plain">&lt;/</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number19 index18 alt2"><code class="xml spaces">        </code><code class="xml plain">&lt;/</code><code class="xml keyword">property</code><code class="xml plain">&gt;</code></div><div class="line number20 index19 alt1"><code class="xml spaces">        </code><code class="xml plain">&lt;</code><code class="xml keyword">property</code> <code class="xml color1">name</code><code class="xml plain">=</code><code class="xml string">"interceptorTypes"</code><code class="xml plain">&gt;</code></div><div class="line number21 index20 alt2"><code class="xml spaces">            </code><code class="xml plain">&lt;</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number22 index21 alt1"><code class="xml spaces">                </code><code class="xml plain">&lt;</code><code class="xml keyword">value</code><code class="xml plain">&gt;bar.baz.SomeInterceptor&lt;/</code><code class="xml keyword">value</code><code class="xml plain">&gt;</code></div><div class="line number23 index22 alt2"><code class="xml spaces">            </code><code class="xml plain">&lt;/</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number24 index23 alt1"><code class="xml spaces">        </code><code class="xml plain">&lt;/</code><code class="xml keyword">property</code><code class="xml plain">&gt;</code></div><div class="line number25 index24 alt2"><code class="xml spaces">    </code><code class="xml plain">&lt;/</code><code class="xml keyword">bean</code><code class="xml plain">&gt;</code></div><div class="line number26 index25 alt1"> </div><div class="line number27 index26 alt2"><code class="xml plain">&lt;/</code><code class="xml keyword">beans</code><code class="xml plain">&gt;</code></div></div></td></tr></tbody></table></div></div>

<p><span class="start-space"></span>
</p><div class="def">
	See example of <span class="name">Spring Framework</span> app <a target="_blank" href="./example-spring-mybatis.html">here</a>.
</div></div>
	<div class="importBlock" p-url="./chapters/06_mybatis.html"><h2><a id="p9">9. MyBatis Integration</a></h2>

<p><span class="start-space"></span>
<span class="title">SqlSession</span>
<br><span class="start-space"></span>You can use <tt>SqlSession</tt> of <span class="name">MyBatis</span> 
by adding <a target="_blank" href="../javadoc/com/gf/components/mybatis/SqlSessionInInvoke.html"><tt>SqlSessionInInvoke</tt></a> filter 
and <tt>SqlSessionFactory</tt> object into <tt>Engine</tt>.
<br><span class="start-space"></span>Example:
</p><div><div id="highlighter_133350" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div><div class="line number28 index27 alt1">28</div><div class="line number29 index28 alt2">29</div><div class="line number30 index29 alt1">30</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java comments">//engine</code></div><div class="line number2 index1 alt1"><code class="java keyword">import</code> <code class="java plain">org.apache.ibatis.session.SqlSessionFactory;</code></div><div class="line number3 index2 alt2"><code class="java keyword">import</code> <code class="java plain">com.gf.components.mybatis.SqlSessionInInvoke;</code></div><div class="line number4 index3 alt1"> </div><div class="line number5 index4 alt2"><code class="java plain">SqlSessionFactory sqlSessionFactory = ... </code></div><div class="line number6 index5 alt1"> </div><div class="line number7 index6 alt2"><code class="java plain">Engine engine = </code><code class="java keyword">new</code> <code class="java plain">Engine();</code></div><div class="line number8 index7 alt1"><code class="java plain">engine.putFilter(SqlSessionInInvoke.</code><code class="java keyword">class</code><code class="java plain">);</code></div><div class="line number9 index8 alt2"><code class="java plain">engine.addToContext(sqlSessionFactory);</code></div><div class="line number10 index9 alt1"><code class="java plain">engine.putHandler(SomeHandler.</code><code class="java keyword">class</code><code class="java plain">);</code></div><div class="line number11 index10 alt2"> </div><div class="line number12 index11 alt1"> </div><div class="line number13 index12 alt2"><code class="java comments">//handler</code></div><div class="line number14 index13 alt1"><code class="java keyword">import</code> <code class="java plain">java.sql.Connection;</code></div><div class="line number15 index14 alt2"><code class="java keyword">import</code> <code class="java plain">org.apache.ibatis.session.SqlSession;</code></div><div class="line number16 index15 alt1"> </div><div class="line number17 index16 alt2"><code class="java color1">@Mapping</code><code class="java plain">(SomeAction.</code><code class="java keyword">class</code><code class="java plain">)</code></div><div class="line number18 index17 alt1"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">SomeHandler </code><code class="java keyword">extends</code> <code class="java plain">Handler&lt;SomeAction&gt;{</code></div><div class="line number19 index18 alt2"><code class="java spaces">    </code> </div><div class="line number20 index19 alt1"><code class="java spaces">    </code><code class="java color1">@Inject</code></div><div class="line number21 index20 alt2"><code class="java spaces">    </code><code class="java plain">Connection connection;</code></div><div class="line number22 index21 alt1"><code class="java spaces">    </code> </div><div class="line number23 index22 alt2"><code class="java spaces">    </code><code class="java color1">@Inject</code></div><div class="line number24 index23 alt1"><code class="java spaces">    </code><code class="java plain">SqlSession session;</code></div><div class="line number25 index24 alt2"> </div><div class="line number26 index25 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java keyword">void</code> <code class="java plain">invoke(SomeAction action) </code><code class="java keyword">throws</code> <code class="java plain">Exception {</code></div><div class="line number27 index26 alt2"><code class="java spaces">        </code><code class="java plain">...</code></div><div class="line number28 index27 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number29 index28 alt2"> </div><div class="line number30 index29 alt1"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div>

<p class="text-align-left"><span class="start-space"></span>
Also you can setup SqlSession's <tt>ExecutorType</tt> in a handler by 
<a target="_blank" href="../javadoc/com/gf/components/mybatis/SqlSessionSettings.html"><tt>SqlSessionSettings</tt></a> annotation:
</p><div><div id="highlighter_796979" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java keyword">import</code> <code class="java plain">org.apache.ibatis.session.ExecutorType;</code></div><div class="line number2 index1 alt1"><code class="java keyword">import</code> <code class="java plain">com.gf.components.mybatis.SqlSessionSettings;</code></div><div class="line number3 index2 alt2"> </div><div class="line number4 index3 alt1"><code class="java color1">@SqlSessionSettings</code><code class="java plain">(execType=ExecutorType.BATCH)</code></div><div class="line number5 index4 alt2"><code class="java color1">@Mapping</code><code class="java plain">(SomeActon.</code><code class="java keyword">class</code><code class="java plain">)</code></div><div class="line number6 index5 alt1"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">SomeHandler </code><code class="java keyword">extends</code> <code class="java plain">Handler&lt;SomeActon&gt;{</code></div><div class="line number7 index6 alt2"> </div><div class="line number8 index7 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java keyword">void</code> <code class="java plain">invoke(SomeActon action) </code><code class="java keyword">throws</code> <code class="java plain">Exception {</code></div><div class="line number9 index8 alt2"><code class="java spaces">        </code><code class="java plain">...</code></div><div class="line number10 index9 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number11 index10 alt2"><code class="java spaces">    </code> </div><div class="line number12 index11 alt1"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div>



<p class="more-top text-align-left"><span class="start-space"></span>
<span class="title">Inject Mappers</span>
<br><span class="start-space"></span>With <tt>SqlSession</tt> you can inject mappers into your handlers by 
<a target="_blank" href="../javadoc/com/gf/components/mybatis/InjectMappers.html"><tt>InjectMappers</tt></a> interceptor:
</p><div><div id="highlighter_63948" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div><div class="line number28 index27 alt1">28</div><div class="line number29 index28 alt2">29</div><div class="line number30 index29 alt1">30</div><div class="line number31 index30 alt2">31</div><div class="line number32 index31 alt1">32</div><div class="line number33 index32 alt2">33</div><div class="line number34 index33 alt1">34</div><div class="line number35 index34 alt2">35</div><div class="line number36 index35 alt1">36</div><div class="line number37 index36 alt2">37</div><div class="line number38 index37 alt1">38</div><div class="line number39 index38 alt2">39</div><div class="line number40 index39 alt1">40</div><div class="line number41 index40 alt2">41</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java comments">//engine</code></div><div class="line number2 index1 alt1"><code class="java keyword">import</code> <code class="java plain">org.apache.ibatis.session.SqlSessionFactory;</code></div><div class="line number3 index2 alt2"><code class="java keyword">import</code> <code class="java plain">com.gf.components.mybatis.SqlSessionInInvoke;</code></div><div class="line number4 index3 alt1"><code class="java keyword">import</code> <code class="java plain">com.gf.components.mybatis.InjectMappers;</code></div><div class="line number5 index4 alt2"> </div><div class="line number6 index5 alt1"><code class="java plain">SqlSessionFactory sqlSessionFactory = ... </code></div><div class="line number7 index6 alt2"> </div><div class="line number8 index7 alt1"><code class="java plain">Engine engine = </code><code class="java keyword">new</code> <code class="java plain">Engine();</code></div><div class="line number9 index8 alt2"><code class="java plain">engine.putFilter(SqlSessionInInvoke.</code><code class="java keyword">class</code><code class="java plain">);</code></div><div class="line number10 index9 alt1"><code class="java plain">engine.putInitializer(</code><code class="java keyword">new</code> <code class="java plain">InjectMappers());</code></div><div class="line number11 index10 alt2"><code class="java plain">engine.addToContext(sqlSessionFactory);</code></div><div class="line number12 index11 alt1"><code class="java plain">engine.putHandler(SomeHandler.</code><code class="java keyword">class</code><code class="java plain">);</code></div><div class="line number13 index12 alt2"> </div><div class="line number14 index13 alt1"> </div><div class="line number15 index14 alt2"><code class="java comments">//mapper</code></div><div class="line number16 index15 alt1"><code class="java keyword">import</code> <code class="java plain">org.apache.ibatis.annotations.Param;</code></div><div class="line number17 index16 alt2"> </div><div class="line number18 index17 alt1"><code class="java keyword">public</code> <code class="java keyword">interface</code> <code class="java plain">DocMapper  {</code></div><div class="line number19 index18 alt2"><code class="java spaces">    </code> </div><div class="line number20 index19 alt1"><code class="java spaces">    </code><code class="java keyword">void</code> <code class="java plain">createDoc(</code><code class="java color1">@Param</code><code class="java plain">(</code><code class="java string">"id"</code><code class="java plain">)</code><code class="java keyword">long</code> <code class="java plain">id, </code><code class="java color1">@Param</code><code class="java plain">(</code><code class="java string">"name"</code><code class="java plain">)String name);</code></div><div class="line number21 index20 alt2"><code class="java spaces">    </code> </div><div class="line number22 index21 alt1"><code class="java spaces">    </code><code class="java keyword">int</code> <code class="java plain">renameDoc(</code><code class="java color1">@Param</code><code class="java plain">(</code><code class="java string">"id"</code><code class="java plain">)</code><code class="java keyword">long</code> <code class="java plain">id, </code><code class="java color1">@Param</code><code class="java plain">(</code><code class="java string">"name"</code><code class="java plain">)String name);</code></div><div class="line number23 index22 alt2"> </div><div class="line number24 index23 alt1"><code class="java plain">}</code></div><div class="line number25 index24 alt2"> </div><div class="line number26 index25 alt1"> </div><div class="line number27 index26 alt2"><code class="java comments">//handler</code></div><div class="line number28 index27 alt1"><code class="java keyword">import</code> <code class="java plain">java.sql.Connection;</code></div><div class="line number29 index28 alt2"><code class="java keyword">import</code> <code class="java plain">org.apache.ibatis.session.SqlSession;</code></div><div class="line number30 index29 alt1"> </div><div class="line number31 index30 alt2"><code class="java color1">@Mapping</code><code class="java plain">(SomeAction.</code><code class="java keyword">class</code><code class="java plain">)</code></div><div class="line number32 index31 alt1"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">SomeHandler </code><code class="java keyword">extends</code> <code class="java plain">Handler&lt;SomeAction&gt;{</code></div><div class="line number33 index32 alt2"><code class="java spaces">    </code> </div><div class="line number34 index33 alt1"><code class="java spaces">    </code><code class="java color1">@Inject</code></div><div class="line number35 index34 alt2"><code class="java spaces">    </code><code class="java plain">DocMapper docMapper;</code></div><div class="line number36 index35 alt1"> </div><div class="line number37 index36 alt2"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java keyword">void</code> <code class="java plain">invoke(SomeAction action) </code><code class="java keyword">throws</code> <code class="java plain">Exception {</code></div><div class="line number38 index37 alt1"><code class="java spaces">        </code><code class="java plain">...</code></div><div class="line number39 index38 alt2"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number40 index39 alt1"> </div><div class="line number41 index40 alt2"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div>


<p><span class="start-space"></span>
</p><div class="def">
	See example of app with <span class="name">MyBatis</span> <a target="_blank" href="./example-spring-mybatis.html">here</a>.
</div></div>
	<div class="importBlock" p-url="./chapters/07_jdbc-tx.html"><h2><a id="p10">10. JDBC and Transactions</a></h2>

<p class="text-align-left"><span class="start-space"></span>
If you have <tt>javax.sql.DataSource</tt> and (or) <tt>javax.transaction.UserTransaction</tt> you can 
use <a target="_blank" href="../javadoc/com/gf/components/jdbc/ConnectionInInvoke.html"><tt>ConnectionInInvoke</tt></a> 
and (or) <a target="_blank" href="../javadoc/com/gf/components/tx/UserTransactionInInvoke.html"><tt>UserTransactionInInvoke</tt></a>
for adding <tt>java.sql.Connection</tt> and (or) <tt>javax.transaction.UserTransaction</tt> into handler's context:
</p><div><div id="highlighter_526076" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div><div class="line number28 index27 alt1">28</div><div class="line number29 index28 alt2">29</div><div class="line number30 index29 alt1">30</div><div class="line number31 index30 alt2">31</div><div class="line number32 index31 alt1">32</div><div class="line number33 index32 alt2">33</div><div class="line number34 index33 alt1">34</div><div class="line number35 index34 alt2">35</div><div class="line number36 index35 alt1">36</div><div class="line number37 index36 alt2">37</div><div class="line number38 index37 alt1">38</div><div class="line number39 index38 alt2">39</div><div class="line number40 index39 alt1">40</div><div class="line number41 index40 alt2">41</div><div class="line number42 index41 alt1">42</div><div class="line number43 index42 alt2">43</div><div class="line number44 index43 alt1">44</div><div class="line number45 index44 alt2">45</div><div class="line number46 index45 alt1">46</div><div class="line number47 index46 alt2">47</div><div class="line number48 index47 alt1">48</div><div class="line number49 index48 alt2">49</div><div class="line number50 index49 alt1">50</div><div class="line number51 index50 alt2">51</div><div class="line number52 index51 alt1">52</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java comments">//impl of DataSourceManager</code></div><div class="line number2 index1 alt1"><code class="java keyword">import</code> <code class="java plain">javax.sql.DataSource;</code></div><div class="line number3 index2 alt2"> </div><div class="line number4 index3 alt1"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">DataSourceManagerImpl </code><code class="java keyword">implements</code> <code class="java plain">DataSourceManager {</code></div><div class="line number5 index4 alt2"> </div><div class="line number6 index5 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java plain">DataSource getDataSource() {</code></div><div class="line number7 index6 alt2"><code class="java spaces">        </code><code class="java keyword">return</code> <code class="java plain">dataSource;</code></div><div class="line number8 index7 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number9 index8 alt2"> </div><div class="line number10 index9 alt1"><code class="java plain">}</code></div><div class="line number11 index10 alt2"> </div><div class="line number12 index11 alt1"> </div><div class="line number13 index12 alt2"><code class="java comments">//impl of TxManager</code></div><div class="line number14 index13 alt1"><code class="java keyword">import</code> <code class="java plain">javax.transaction.UserTransaction;</code></div><div class="line number15 index14 alt2"> </div><div class="line number16 index15 alt1"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">TxManagerImpl </code><code class="java keyword">implements</code> <code class="java plain">TxManager {</code></div><div class="line number17 index16 alt2"> </div><div class="line number18 index17 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java plain">UserTransaction getUserTransaction() {</code></div><div class="line number19 index18 alt2"><code class="java spaces">        </code><code class="java keyword">return</code> <code class="java plain">userTx;</code></div><div class="line number20 index19 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number21 index20 alt2"> </div><div class="line number22 index21 alt1"><code class="java plain">}</code></div><div class="line number23 index22 alt2"> </div><div class="line number24 index23 alt1"><code class="java comments">//engine</code></div><div class="line number25 index24 alt2"><code class="java plain">DataSourceManagerImpl dataSourceManagerImpl = ...;</code></div><div class="line number26 index25 alt1"><code class="java plain">TxManagerImpl txManagerImpl = ...;</code></div><div class="line number27 index26 alt2"><code class="java plain">Engine engine = </code><code class="java keyword">new</code> <code class="java plain">Engine();</code></div><div class="line number28 index27 alt1"><code class="java plain">engine.addToContext(dataSourceManagerImpl);</code></div><div class="line number29 index28 alt2"><code class="java plain">engine.addToContext(txManagerImpl);</code></div><div class="line number30 index29 alt1"><code class="java plain">engine.putFilter(ConnectionInInvoke.</code><code class="java keyword">class</code><code class="java plain">);</code></div><div class="line number31 index30 alt2"><code class="java plain">engine.putFilter(UserTransactionInInvoke.</code><code class="java keyword">class</code><code class="java plain">);</code></div><div class="line number32 index31 alt1"><code class="java plain">engine.putHandler(SomeHandler.</code><code class="java keyword">class</code><code class="java plain">);</code></div><div class="line number33 index32 alt2"> </div><div class="line number34 index33 alt1"> </div><div class="line number35 index34 alt2"><code class="java comments">//handler</code></div><div class="line number36 index35 alt1"><code class="java keyword">import</code> <code class="java plain">java.sql.Connection;</code></div><div class="line number37 index36 alt2"><code class="java keyword">import</code> <code class="java plain">javax.transaction.UserTransaction;</code></div><div class="line number38 index37 alt1"> </div><div class="line number39 index38 alt2"><code class="java color1">@Mapping</code><code class="java plain">(SomeAction.</code><code class="java keyword">class</code><code class="java plain">)</code></div><div class="line number40 index39 alt1"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">SomeHandler </code><code class="java keyword">extends</code> <code class="java plain">Handler&lt;SomeAction&gt;{</code></div><div class="line number41 index40 alt2"><code class="java spaces">    </code> </div><div class="line number42 index41 alt1"><code class="java spaces">    </code><code class="java color1">@Inject</code></div><div class="line number43 index42 alt2"><code class="java spaces">    </code><code class="java plain">UserTransaction userTx;</code></div><div class="line number44 index43 alt1"><code class="java spaces">    </code> </div><div class="line number45 index44 alt2"><code class="java spaces">    </code><code class="java color1">@Inject</code></div><div class="line number46 index45 alt1"><code class="java spaces">    </code><code class="java plain">Connection connection;</code></div><div class="line number47 index46 alt2"> </div><div class="line number48 index47 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java keyword">void</code> <code class="java plain">invoke(SomeAction action) </code><code class="java keyword">throws</code> <code class="java plain">Exception {</code></div><div class="line number49 index48 alt2"><code class="java spaces">        </code><code class="java plain">...</code></div><div class="line number50 index49 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number51 index50 alt2"> </div><div class="line number52 index51 alt1"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
	<div class="importBlock" p-url="./chapters/09_examples.html"><h2><a id="p11">11. Examples</a></h2>

<p><span class="start-space"></span>
You can download the examples from <a target="_blank" href="https://code.google.com/p/green-forest/downloads/list">download page</a>.
<br><span class="start-space"></span>The zip archive with name like <tt>"green-forest-X.X-all.zip"</tt> contains all examples in folder "examples". 

</p><p><span class="start-space"></span>
Documentation about examples:
</p><ul>
	<li>
		<a target="_blank" href="./example-jee.html">
			JEE application with Green-forest example
		</a>
	</li>
	<li>
		<a target="_blank" href="./example-spring-mybatis.html">
			Spring Framework application with Green-forest Framework and MyBatis example
		</a>
	</li>
	<li>
		<a target="_blank" href="./example-servlet-jdbc.html">
			Servlet/JSP application with Green-forest Framework and JDBC example
		</a>
	</li>
</ul></div>
	<div class="importBlock" p-url="./chapters/10_known-issues.html"><h2><a id="p12">12. Known Issues</a></h2>

<p class="text-align-left"><span class="start-space"></span>
<span class="title">Need of setup of ClassScanner for JBoss AS</span>
<br><span class="start-space"></span>
In JBoss AS for using Engine's <a target="_blank" href="../javadoc/com/gf/core/Engine.html#scanAndPut%28java.lang.String%29">scanAndPut</a> method
you need this additional libraries (include them into CLASSPATH):
</p><ul>
	<li><a target="_blank" href="http://code.google.com/p/reflections/">Reflections</a></li>
	<li><a target="_blank" href="http://code.google.com/p/guava-libraries/">The Guava project</a></li>
	<li><a target="_blank" href="http://www.csg.ci.i.u-tokyo.ac.jp/%7Echiba/javassist/">Javassist</a></li>
</ul>

<p><span class="start-space"></span>
This additional libraries are used in <a target="_blank" href="./example-jee.html">JEE example application</a>.

</p><p><span class="start-space"></span>
Or you can implement your own <a target="_blank" href="../javadoc/com/gf/extra/scan/ClassScanner.html">ClassScanner</a>.</p></div>
	<div class="importBlock" p-url="./chapters/11_best-practies.html"><h2><a id="p13">13. Best Practices</a></h2>
 	
 	<p><span class="start-space"></span>
	<span class="title">Use Action for additional logic</span>
	<br><span class="start-space"></span><tt>Action</tt> can be not only the data container: you can use it for validation and standardization's things.
	<br><span class="start-space"></span>Example of additional action's logic:
	</p><div><div id="highlighter_316497" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div><div class="line number28 index27 alt1">28</div><div class="line number29 index28 alt2">29</div><div class="line number30 index29 alt1">30</div><div class="line number31 index30 alt2">31</div><div class="line number32 index31 alt1">32</div><div class="line number33 index32 alt2">33</div><div class="line number34 index33 alt1">34</div><div class="line number35 index34 alt2">35</div><div class="line number36 index35 alt1">36</div><div class="line number37 index36 alt2">37</div><div class="line number38 index37 alt1">38</div><div class="line number39 index38 alt2">39</div><div class="line number40 index39 alt1">40</div><div class="line number41 index40 alt2">41</div><div class="line number42 index41 alt1">42</div><div class="line number43 index42 alt2">43</div><div class="line number44 index43 alt1">44</div><div class="line number45 index44 alt2">45</div><div class="line number46 index45 alt1">46</div><div class="line number47 index46 alt2">47</div><div class="line number48 index47 alt1">48</div><div class="line number49 index48 alt2">49</div><div class="line number50 index49 alt1">50</div><div class="line number51 index50 alt2">51</div><div class="line number52 index51 alt1">52</div><div class="line number53 index52 alt2">53</div><div class="line number54 index53 alt1">54</div><div class="line number55 index54 alt2">55</div><div class="line number56 index55 alt1">56</div><div class="line number57 index56 alt2">57</div><div class="line number58 index57 alt1">58</div><div class="line number59 index58 alt2">59</div><div class="line number60 index59 alt1">60</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java comments">//1. create common interface for validation</code></div><div class="line number2 index1 alt1"><code class="java keyword">public</code> <code class="java keyword">interface</code> <code class="java plain">HasDocNames {</code></div><div class="line number3 index2 alt2"> </div><div class="line number4 index3 alt1"><code class="java spaces">    </code><code class="java plain">List&lt;String&gt; getNames();</code></div><div class="line number5 index4 alt2"> </div><div class="line number6 index5 alt1"><code class="java plain">}</code></div><div class="line number7 index6 alt2"> </div><div class="line number8 index7 alt1"><code class="java comments">//2. add interface to acitons:</code></div><div class="line number9 index8 alt2"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">CreateDocs </code><code class="java keyword">extends</code> <code class="java plain">Action&lt;List&lt;String&gt;, List&lt;Doc&gt;&gt; </code></div><div class="line number10 index9 alt1"><code class="java spaces">    </code><code class="java keyword">implements</code> <code class="java plain">HasDocNames {</code></div><div class="line number11 index10 alt2"> </div><div class="line number12 index11 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java plain">CreateDocs(List&lt;String&gt; names) {</code></div><div class="line number13 index12 alt2"><code class="java spaces">        </code><code class="java keyword">super</code><code class="java plain">(names);</code></div><div class="line number14 index13 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number15 index14 alt2"><code class="java spaces">    </code> </div><div class="line number16 index15 alt1"><code class="java spaces">    </code><code class="java comments">//additional logic</code></div><div class="line number17 index16 alt2"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java plain">List&lt;String&gt; getNames() {</code></div><div class="line number18 index17 alt1"><code class="java spaces">        </code><code class="java keyword">return</code> <code class="java plain">input;</code></div><div class="line number19 index18 alt2"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number20 index19 alt1"> </div><div class="line number21 index20 alt2"><code class="java plain">}</code></div><div class="line number22 index21 alt1"> </div><div class="line number23 index22 alt2"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">RenameDoc </code><code class="java keyword">extends</code> <code class="java plain">Action&lt;Doc, Void&gt; </code></div><div class="line number24 index23 alt1"><code class="java spaces">    </code><code class="java keyword">implements</code> <code class="java plain">HasDocNames {</code></div><div class="line number25 index24 alt2"><code class="java spaces">    </code> </div><div class="line number26 index25 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java plain">RenameDoc(</code><code class="java keyword">int</code> <code class="java plain">id, String newName){</code></div><div class="line number27 index26 alt2"><code class="java spaces">        </code><code class="java keyword">this</code><code class="java plain">(</code><code class="java keyword">new</code> <code class="java plain">Doc(id, newName));</code></div><div class="line number28 index27 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number29 index28 alt2"> </div><div class="line number30 index29 alt1"><code class="java spaces">    </code><code class="java comments">//additional logic</code></div><div class="line number31 index30 alt2"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java plain">List&lt;String&gt; getNames() {</code></div><div class="line number32 index31 alt1"><code class="java spaces">        </code><code class="java keyword">if</code><code class="java plain">(input != </code><code class="java keyword">null</code><code class="java plain">){</code></div><div class="line number33 index32 alt2"><code class="java spaces">            </code><code class="java keyword">return</code> <code class="java plain">Util.list(input.name);</code></div><div class="line number34 index33 alt1"><code class="java spaces">        </code><code class="java plain">}</code></div><div class="line number35 index34 alt2"><code class="java spaces">        </code><code class="java keyword">return</code> <code class="java keyword">null</code><code class="java plain">;</code></div><div class="line number36 index35 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number37 index36 alt2"> </div><div class="line number38 index37 alt1"><code class="java plain">}</code></div><div class="line number39 index38 alt2"> </div><div class="line number40 index39 alt1"><code class="java comments">//3. use additional logic in validation</code></div><div class="line number41 index40 alt2"><code class="java color1">@Mapping</code><code class="java plain">(HasDocNames.</code><code class="java keyword">class</code><code class="java plain">)</code></div><div class="line number42 index41 alt1"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">CheckDocNameInterceptor </code><code class="java keyword">extends</code> <code class="java plain">Interceptor&lt;Action&lt;?,?&gt;&gt;{</code></div><div class="line number43 index42 alt2"> </div><div class="line number44 index43 alt1"><code class="java spaces">    </code><code class="java color1">@Override</code></div><div class="line number45 index44 alt2"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java keyword">void</code> <code class="java plain">invoke(Action&lt;?, ?&gt; action, InterceptorChain chain) </code></div><div class="line number46 index45 alt1"><code class="java spaces">        </code><code class="java keyword">throws</code> <code class="java plain">Exception {</code></div><div class="line number47 index46 alt2"><code class="java spaces">        </code> </div><div class="line number48 index47 alt1"><code class="java spaces">        </code><code class="java plain">HasDocNames hasDocNames = ((HasDocNames)action);</code></div><div class="line number49 index48 alt2"><code class="java spaces">        </code><code class="java plain">List&lt;String&gt; names = hasDocNames.getNames();</code></div><div class="line number50 index49 alt1"><code class="java spaces">        </code> </div><div class="line number51 index50 alt2"><code class="java spaces">        </code><code class="java keyword">boolean</code> <code class="java plain">isValid = validateNames(names);</code></div><div class="line number52 index51 alt1"><code class="java spaces">        </code> </div><div class="line number53 index52 alt2"><code class="java spaces">        </code><code class="java keyword">if</code><code class="java plain">( ! isValid) </code><code class="java keyword">throw</code> <code class="java keyword">new</code> <code class="java plain">InvalidNameException();</code></div><div class="line number54 index53 alt1"><code class="java spaces">        </code> </div><div class="line number55 index54 alt2"><code class="java spaces">        </code><code class="java plain">chain.doNext();</code></div><div class="line number56 index55 alt1"><code class="java spaces">        </code> </div><div class="line number57 index56 alt2"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number58 index57 alt1"> </div><div class="line number59 index58 alt2"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div></div>
	<div class="importBlock" p-url="./chapters/12_license.html"><h2><a id="p14">14. License</a></h2>

<p><span class="start-space"></span>
Licensed under the <a target="_blank" href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.
<br><span class="start-space"></span>This library is free for any use.</p></div>
 	

</div>

<div class="importBlock" p-url="./chapters/footer.html">
<div id="copyright">
<a href="http://code.google.com/p/green-forest/"><span class="name">Green-forest Framework</span></a> was originally created in 2011 and is still maintained by Evgeny Dolganov. 
Copyright 2011-2013 <a target="_blank" href="http://ru.linkedin.com/pub/evgeny-dolganov/17/a71/464">Evgeny Dolganov</a>.
</div>

<div id="toTop">Back to Top</div></div>


</body></html>